#!user/bin/env python3
# -- coding: utf-8 --
# @Createtime：2023/8/30 16:06
# @Updatetime：16:06
# @Author：Test008
# @File：14-内嵌网页处理
# @Description：
import time

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get('https://mail.163.com')
driver.maximize_window()
driver.implicitly_wait(3)

# <iframe> 标签创建包含另一个文档的行内框架。
# 登录账号密码再在frame内嵌页里面，需要先跳转
# 1》定位到 iframe 元素
iframe = driver.find_element(By.CSS_SELECTOR, '#loginDiv iframe')
# 2》 跳转到frame
driver.switch_to.frame(iframe)
# 3》操作
email_button = driver.find_element(By.CSS_SELECTOR, '.j-inputtext.dlemail.j-nameforslide').send_keys(45678)
pwd_button = driver.find_element(By.CSS_SELECTOR, '.j-inputtext.dlpwd').send_keys(45678)
login_button = driver.find_element(By.CSS_SELECTOR, '.j-power-btn.f-cb.loginbox>a').click()
# 4》跳出
# driver.switch_to.default_content()  # 跳到最外层页面
driver.switch_to.parent_frame()  # 跳到父级 frame 元素
time.sleep(2)
# 5》点击外层图片内容，查看是否跳出
theme_item = driver.find_element(By.CSS_SELECTOR, '#mailgg__10241024_0 .theme-item-inner:nth-child(1)>a').click()

time.sleep(2)
driver.quit()
